Abstraction can be achieved with either abstract classes or
interfaces.
2.5.20.3 Inheritance
Inheritance is a feature in which one object acquires all the
properties and behaviors of a parent object. Inheritance promotes
the reusability of the code as we can have one contract at the top
level with generic features and many child contracts inheriting those
as well as more features of their own.
In the following example, we have two contracts. The first one is the
parent contract and the second one is a child contract.
This behavior of the same function working differently in the parent
and the child contract is called function overriding, and it uses the
virtual keyword in the parent contract and the override keyword in
the child contract.
The following is an example of function overriding:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
contract Mammal {
function mammalFunction() public pure virtual returns(string
memory) {
return “Mammals produce offspring by directly giving birth
and females have mammary glands”;
}
}
contract SpecialMammal is Mammal {
function mammalFunction() public pure override
returns(string memory) {
return “Humans are special mammals who can speak and walk
with two legs”;
}
}